﻿using System;
using System.Threading.Tasks;
using Iot.Shared.Model;

namespace Iot.Shared.EventBusSend;

/// <summary>
/// </summary>
public interface IEventBusSend
{
    protected ValueTask ProtectedSend<T>(T data) where T : BusModel;

    ValueTask SendAsync<T>(T data, DateTimeOffset? timeStamp = null) where T : BusModel
    {
        ArgumentNullException.ThrowIfNull(data);
        data.TimeStamp = timeStamp ?? DateTimeOffset.Now;
        return ProtectedSend(data);
    }

    /// <summary>
    ///     发送双精度小数型模拟量数据发送
    /// </summary>
    /// <param name="data"></param>
    /// <param name="timeStamp"></param>
    /// <returns></returns>
    ValueTask SendAsync(FloatBusModel data, DateTimeOffset? timeStamp = null)
    {
        return SendAsync<FloatBusModel>(data, timeStamp);
    }

    /// <summary>
    ///     发送整型模拟量数据发送
    /// </summary>
    /// <param name="data"></param>
    /// <param name="timeStamp"></param>
    /// <returns></returns>
    ValueTask SendAsync(IntegerBusModel data, DateTimeOffset? timeStamp = null)
    {
        return SendAsync<IntegerBusModel>(data, timeStamp);
    }

    /// <summary>
    ///     开关量数据发送
    /// </summary>
    /// <param name="data"></param>
    /// <param name="timeStamp"></param>
    /// <returns></returns>
    ValueTask SendAsync(SwitchBusModel data, DateTimeOffset? timeStamp = null)
    {
        return SendAsync<SwitchBusModel>(data, timeStamp);
    }

    /// <summary>
    ///     枚举数据
    /// </summary>
    /// <param name="data"></param>
    /// <param name="timeStamp"></param>
    /// <returns></returns>
    ValueTask SendAsync(EnumBusModel data, DateTimeOffset? timeStamp = null)
    {
        return SendAsync<EnumBusModel>(data, timeStamp);
    }
}